Loading the required libraries ,
library(plyr)
library(dplyr)##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:plyr':
##
## arrange, count, desc, failwith, id, mutate, rename, summarise,
## summarize
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(plotly)##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following objects are masked from 'package:plyr':
##
## arrange, mutate, rename, summarise
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(DT)
library(tidyr)
library(gridExtra)##
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
##
## combine
setwd("C:/Users/Deepak kumar/Downloads/R/Hospital Ratings")hos=read.csv("Hospital General Information.csv",stringsAsFactors = FALSE,header=TRUE)
glimpse(hos)## Observations: 4,812
## Variables: 28
## $ Provider.ID <int> ...
## $ Hospital.Name <chr> ...
## $ Address <chr> ...
## $ City <chr> ...
## $ State <chr> ...
## $ ZIP.Code <int> ...
## $ County.Name <chr> ...
## $ Phone.Number <dbl> ...
## $ Hospital.Type <chr> ...
## $ Hospital.Ownership <chr> ...
## $ Emergency.Services <chr> ...
## $ Meets.criteria.for.meaningful.use.of.EHRs <chr> ...
## $ Hospital.overall.rating <chr> ...
## $ Hospital.overall.rating.footnote <chr> ...
## $ Mortality.national.comparison <chr> ...
## $ Mortality.national.comparison.footnote <chr> ...
## $ Safety.of.care.national.comparison <chr> ...
## $ Safety.of.care.national.comparison.footnote <chr> ...
## $ Readmission.national.comparison <chr> ...
## $ Readmission.national.comparison.footnote <chr> ...
## $ Patient.experience.national.comparison <chr> ...
## $ Patient.experience.national.comparison.footnote <chr> ...
## $ Effectiveness.of.care.national.comparison <chr> ...
## $ Effectiveness.of.care.national.comparison.footnote <chr> ...
## $ Timeliness.of.care.national.comparison <chr> ...
## $ Timeliness.of.care.national.comparison.footnote <chr> ...
## $ Efficient.use.of.medical.imaging.national.comparison <chr> ...
## $ Efficient.use.of.medical.imaging.national.comparison.footnote <chr> ...
dim(hos)## [1] 4812 28
head(hos)## Provider.ID Hospital.Name Address
## 1 10001 SOUTHEAST ALABAMA MEDICAL CENTER 1108 ROSS CLARK CIRCLE
## 2 10005 MARSHALL MEDICAL CENTER SOUTH 2505 U S HIGHWAY 431 NORTH
## 3 10006 ELIZA COFFEE MEMORIAL HOSPITAL 205 MARENGO STREET
## 4 10007 MIZELL MEMORIAL HOSPITAL 702 N MAIN ST
## 5 10008 CRENSHAW COMMUNITY HOSPITAL 101 HOSPITAL CIRCLE
## 6 10011 ST VINCENT'S EAST 50 MEDICAL PARK EAST DRIVE
## City State ZIP.Code County.Name Phone.Number Hospital.Type
## 1 DOTHAN AL 36301 HOUSTON 3347938701 Acute Care Hospitals
## 2 BOAZ AL 35957 MARSHALL 2565938310 Acute Care Hospitals
## 3 FLORENCE AL 35631 LAUDERDALE 2567688400 Acute Care Hospitals
## 4 OPP AL 36467 COVINGTON 3344933541 Acute Care Hospitals
## 5 LUVERNE AL 36049 CRENSHAW 3343353374 Acute Care Hospitals
## 6 BIRMINGHAM AL 35235 JEFFERSON 2058383122 Acute Care Hospitals
## Hospital.Ownership Emergency.Services
## 1 Government - Hospital District or Authority Yes
## 2 Government - Hospital District or Authority Yes
## 3 Government - Hospital District or Authority Yes
## 4 Voluntary non-profit - Private Yes
## 5 Proprietary Yes
## 6 Voluntary non-profit - Private Yes
## Meets.criteria.for.meaningful.use.of.EHRs Hospital.overall.rating
## 1 Y 3
## 2 Y 3
## 3 Y 2
## 4 Y 2
## 5 Y 3
## 6 Y 2
## Hospital.overall.rating.footnote Mortality.national.comparison
## 1 Same as the national average
## 2 Below the national average
## 3 Below the national average
## 4 Same as the national average
## 5 Same as the national average
## 6 Same as the national average
## Mortality.national.comparison.footnote
## 1
## 2
## 3
## 4
## 5
## 6
## Safety.of.care.national.comparison
## 1 Above the national average
## 2 Same as the national average
## 3 Same as the national average
## 4 Not Available
## 5 Not Available
## 6 Below the national average
## Safety.of.care.national.comparison.footnote
## 1
## 2
## 3
## 4 Results are not available for this reporting period
## 5 Results are not available for this reporting period
## 6
## Readmission.national.comparison Readmission.national.comparison.footnote
## 1 Same as the national average
## 2 Above the national average
## 3 Same as the national average
## 4 Below the national average
## 5 Same as the national average
## 6 Same as the national average
## Patient.experience.national.comparison
## 1 Below the national average
## 2 Same as the national average
## 3 Below the national average
## 4 Same as the national average
## 5 Not Available
## 6 Below the national average
## Patient.experience.national.comparison.footnote
## 1
## 2
## 3
## 4
## 5 Results are not available for this reporting period
## 6
## Effectiveness.of.care.national.comparison
## 1 Same as the national average
## 2 Same as the national average
## 3 Same as the national average
## 4 Below the national average
## 5 Same as the national average
## 6 Below the national average
## Effectiveness.of.care.national.comparison.footnote
## 1
## 2
## 3
## 4
## 5
## 6
## Timeliness.of.care.national.comparison
## 1 Same as the national average
## 2 Above the national average
## 3 Above the national average
## 4 Above the national average
## 5 Above the national average
## 6 Same as the national average
## Timeliness.of.care.national.comparison.footnote
## 1
## 2
## 3
## 4
## 5
## 6
## Efficient.use.of.medical.imaging.national.comparison
## 1 Same as the national average
## 2 Below the national average
## 3 Same as the national average
## 4 Not Available
## 5 Not Available
## 6 Same as the national average
## Efficient.use.of.medical.imaging.national.comparison.footnote
## 1
## 2
## 3
## 4 Results are not available for this reporting period
## 5 Results are not available for this reporting period
## 6
hos$Phone.Number=NULL
hos$Address=NULL
names(hos)[names(hos)=="County.Name"]="Country.Name"
length(unique(hos$Country.Name))## [1] 1564
length(unique(hos$State))## [1] 56
temp=hos %>% select(Hospital.Name,Hospital.Type) %>% group_by(Hospital.Type)
temp=ddply(temp,.(Hospital.Type),summarise,count=n())
plot_ly(temp,x=~temp$Hospital.Type,y=~temp$count,color=temp$Hospital.Type,type="bar") %>% layout(title="Number of Hospitals by Type",xaxis=list(title="Type"),yaxis=list(title="Count"))temp=hos %>% select(Hospital.Name,Hospital.Ownership) %>% group_by(Hospital.Ownership)
temp=ddply(temp,.(Hospital.Ownership),summarise,count=n())
plot_ly(temp,x=~temp$Hospital.Ownership,y=~temp$count,color=temp$Hospital.Ownership,type="bar") %>% layout(title="Number of Hospitals by Ownership",xaxis=list(title="Ownership"),yaxis=list(title="Count"),showlegend=FALSE)## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
Let us get to know how many hospitals in each type are owned by Gov/agency/NonProfit/Proprietary.
temp=as.data.frame(table(hos$Hospital.Type,hos$Hospital.Ownership))
temp=temp%>% group_by(Var2)
q=ggplot(temp,aes(Var2,Freq,fill=Var1))+geom_bar(stat="identity")+theme(axis.text.x =element_text(angle=90))+labs(x="Ownership",y="Count",fill="Hospital Type")+ggtitle("Count of Hospital in each Type and Ownership")
ggplotly(q)## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`
Remarks:
temp=hos %>% filter(Hospital.overall.rating==5) %>% group_by(Hospital.Type,Hospital.Ownership) %>% summarise(total=n())
ggplot(temp,aes(Hospital.Type,total,fill=Hospital.Type))+geom_bar(stat="identity")+facet_wrap(~Hospital.Ownership)+theme(legend.position="None",axis.text.x = element_text(angle=90))+ggtitle("Hospital Type and Ownership distribution with Rating 5")Observations:
temp=ddply(hos,.(State),summarise,total=n()) %>% arrange(desc(total))
datatable(temp)temp=hos %>% filter(hos$State=="TX")
length(unique(temp$Country.Name))## [1] 183
temp=ddply(temp,.(Country.Name),summarise,total=n()) %>% arrange(desc(total))
datatable(temp)temp=hos %>% filter(hos$State=="TX")
temp=ddply(temp,.(Hospital.Type,Hospital.Ownership),summarise,total=n()) %>% arrange(desc(total))
ggplot(temp,aes(Hospital.Type,total,fill=Hospital.Ownership))+geom_bar(stat="identity")+theme(axis.text.x = element_text(angle=90))+labs(x="Hospital Type",y="Total",fill="Ownership")+ggtitle("Distribution of Hospital Type and Ownership in Texas")Observations:
temp=hos %>% filter(State=="TX" & Hospital.Type=="Childrens")
datatable(temp)temp %>% group_by(Country.Name,Hospital.Ownership,Emergency.Services) %>% summarise(count=n()) %>% ggplot(aes(Country.Name,count,fill=Hospital.Ownership))+geom_bar(stat="identity")+labs(x="Country Name",y="Count",fill="Ownership")+theme(axis.text.x = element_text(angle=90))+ggtitle("Children Hospital in TX")+facet_wrap(~Emergency.Services)Observations: